package com.lei.zktwo;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.lei.mvptwozk.glide.GlidUtlis;
import com.lei.zktwo.adapter.MyAdapter;
import com.lei.zktwo.fragment.Fragment1;
import com.lei.zktwo.fragment.Fragment2;

import java.util.ArrayList;
import java.util.List;

public class ZhuActivity extends AppCompatActivity {
    private Fragment1 fragment1;
    private Fragment2 fragment2;
    private TextView tv1_tc;
    private TextView tv1_fx;
    private ViewPager fl;
    private ImageView iv1;
    private CheckBox cb1_ax;
    private MyAdapter adapter;
    private List<Fragment> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu);
        initView();
    }

    private void showfrag(Fragment fragment) {
        getSupportFragmentManager().beginTransaction()
                .hide(fragment1)
                .hide(fragment2)
                .show(fragment)
                .commit();
    }

    private void initView() {
        fragment1 = new Fragment1();
        fragment2 = new Fragment2();
        tv1_tc = (TextView) findViewById(R.id.tv1_tc);
        tv1_fx = (TextView) findViewById(R.id.tv1_fx);
        fl = (ViewPager) findViewById(R.id.fl);
        iv1 = (ImageView) findViewById(R.id.iv1_sss);
        cb1_ax = (CheckBox) findViewById(R.id.cb1_ax);
        list.add(fragment1);
        list.add(fragment2);
        adapter = new MyAdapter(getSupportFragmentManager(),list);
        fl.setAdapter(adapter);
        fl.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position==0){
                    showfrag(fragment1);
                    tv1_fx.setTextColor(Color.GRAY);
                    tv1_fx.setTextSize(16);
                    tv1_tc.setTextColor(Color.WHITE);
                    tv1_tc.setTextSize(20);
                }else if (position==1){
                    showfrag(fragment2);
                    tv1_fx.setTextColor(Color.WHITE);
                    tv1_fx.setTextSize(20);
                    tv1_tc.setTextColor(Color.GRAY);
                    tv1_tc.setTextSize(16);
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
//        getSupportFragmentManager()
//                .beginTransaction()
//                .add(R.id.fl,fragment1)
//                .add(R.id.fl,fragment2).commit();
//        showfrag(fragment1);

        tv1_tc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showfrag(fragment1);
                tv1_fx.setTextColor(Color.GRAY);
                tv1_fx.setTextSize(16);
                tv1_tc.setTextColor(Color.WHITE);
                tv1_tc.setTextSize(20);
            }
        });
        tv1_fx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showfrag(fragment2);
                tv1_fx.setTextColor(Color.WHITE);
                tv1_fx.setTextSize(20);
                tv1_tc.setTextColor(Color.GRAY);
                tv1_tc.setTextSize(16);
            }
        });
        GlidUtlis.Yuan(this,"http://www.qubaobei.com/ios/cf/uploadfile/132/9/8289.jpg",iv1);
    }
}
